n = input()
d = []
m = 0

if 1000 <= int(n) <= 9999:
    for w in range(len(n)):
     for s in range(5-w):
      i = n[s-1:s+w]
      if i != "":
       d.append(i)

    def check(num):
        if num == 1:
            return False
        for i in range(2, num):
            if num % i == 0:
                return False
        return True
       
    for i, a in enumerate(d):
     if check(int(a)) and int(m) <= int(a):
         m = a
print(m)

